package com.wswy.wzcx.ui.car

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.support.v7.app.AppCompatDialog
import android.view.Gravity
import com.blankj.utilcode.util.SizeUtils
import com.wswy.wzcx.R
import com.wswy.wzcx.utils.FileUtils
import com.wswy.wzcx.widget.drawable.PicFrameDrawable
import com.wzcx.orclib.MaskConfig
import com.wzcx.orclib.PhotoAgent
import kotlinx.android.synthetic.main.dialog_car_no_discern.*

class CarNoDiscernDialog (context: Context): AppCompatDialog(context) {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        setContentView(R.layout.dialog_car_no_discern)


        img_pic.background = PicFrameDrawable(context)

        btn_upload.setOnClickListener {
            //LoadingDialog(context,"识别中").show()

            getStartIntent()?.let {
                onStartPhoto?.invoke(it)
            }

        }
    }

    var onStartPhoto:((Intent)->Unit)?=null

    private fun getStartIntent():Intent?{
        val maskConfig = MaskConfig()
        maskConfig.cardTitle = "中华人民共和国机动车行驶证"
        maskConfig.gravity = Gravity.LEFT
        maskConfig.width = SizeUtils.dp2px(72f)
        maskConfig.height = SizeUtils.dp2px(72f)
        maskConfig.cardHint = "请将行驶证边缘对准边框"
        return PhotoAgent
                .getPhotoIntent(context, FileUtils.getSaveFile(context).absolutePath, maskConfig)

    }

}